#from distutils.core import setup
#from distutils.extension import Extension
#from setuptools import setup
#from setuptools.extension import Extension

from numpy.distutils.core import setup
from numpy.distutils.extension import Extension


import sys
from os.path import join

try:
    import numpy
except ImportError:
    print "numpy must be installed to build pywcsgrid."
    print "ABORTING."
    sys.exit(1)

try:
    numpy_include = numpy.get_include()
except AttributeError:
    numpy_include = numpy.get_numpy_include()



from numpy.distutils.misc_util import Configuration

#config = Configuration('pgnumb', "", None)

#config.add_library('pgnumb',
#                   sources=["pgnumb.f"],
#                   )

#import glob
#tpm_sources = glob.glob("tpm/*.c")

def main():
    #dolocal()
    WCSLIBDIR="../wcslib-4.3/"
    setup(name = "pywcsgrid",
          version = "0.1b1",
          description = "",
          author = "Jae-Joon Lee",
          maintainer_email = "lee.j.joon@gmail.com",
          license = "BSD",
          platforms = ["Linux","Mac OS X"], 
          packages = ['pywcsgrid'],
          package_dir={'pywcsgrid':'lib'},

          libraries=[["pgsbox",
                      dict(sources=[WCSLIBDIR+"pgsbox/"+s for s in ["pgsbox.f","cpgsbox.c", "pgwcsl.c", "pgcrfn.f"]],
                           include_dirs=[WCSLIBDIR, WCSLIBDIR+'C',
                                         WCSLIBDIR+'pgsbox']
                           )],
                     ],
          
          ext_modules=[ Extension("pywcsgrid._wcsgrid",
                                  ["src/_wcsgrid.pyx"],
                                  language="f77",
                                  include_dirs=[WCSLIBDIR,
                                                WCSLIBDIR+'src',
                                                WCSLIBDIR+'C',
                                                WCSLIBDIR+'pgsbox',
                                                "src",
                                                numpy_include,
                                                ],
                                  library_dirs=[WCSLIBDIR+'C',], # "../pgsbox"
                                  libraries=["pgsbox", "wcs-4.3"], #, "pgnumb" , "coordconv"
                                  )
                        ],
          )

if __name__ == "__main__":
    main()
